//
//  ByNoticeDetailHeadView.m
//  caipiao_ios
//
//  Created by mc on 2018/8/16.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByNoticeDetailHeadView.h"
#import "ByNoticeTitleView.h"
#import "ByNoticeCirclesView.h"
#import "ByHomeTitleValueView.h"


@implementation ByNoticeDetailHeadView

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = BY_BACKGROUND_COLOR;
        UIImageView *redView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 80)];
        redView.image = [UIImage imageNamed:@"kaijaingxiangqingbeijing开奖公告"];
        [self addSubview:redView];
        
    }
    return self;
}

- (void)setNetModel:(ByNetModel *)netModel{
    _netModel = netModel;
    
    UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, SCREEN_WIDTH - 20, 180)];
    [self addSubview:backgroundView];
    backgroundView.backgroundColor = [UIColor whiteColor];
    backgroundView.layer.cornerRadius = 9;
    
    ByNoticeTitleView *titleView = [[ByNoticeTitleView alloc] init];
    [backgroundView addSubview:titleView];
    [titleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(0);
        make.right.equalTo(backgroundView).offset(0);
        make.top.equalTo(backgroundView).offset(15);
        make.height.mas_equalTo(@15);
    }];
    if (_netModel.category_id.integerValue == 1001) {
        titleView.titleLabel.text = @"双色球";
    }else if (_netModel.category_id.integerValue == 2001){
        titleView.titleLabel.text = @"大乐透";
    }
    titleView.timeLabel.text = [NSString stringWithFormat:@"第%@期 %@", _netModel.number ,_netModel.open_time];
    
    
    ByNoticeCirclesView *circlesView = [[ByNoticeCirclesView alloc] init];
    [backgroundView addSubview:circlesView];
    [circlesView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(0);
        make.top.equalTo(titleView.mas_bottom).offset(5);
        make.right.equalTo(backgroundView).offset(-40);
        make.height.mas_equalTo(@60);
    }];
    circlesView.itemsAry = _netModel.numArray;
    
    
    ByDottedLineView *line = [[ByDottedLineView alloc] init];
    line.direction = DottedLineViewDirectionHorizontalFromRight;
    line.lineColor = BY_LINE_COLOR;
    line.lengthPattern = @[@4, @3];
    [backgroundView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(0);
        make.right.equalTo(backgroundView).offset(0);
        make.centerY.equalTo(backgroundView).offset(0);
        make.height.mas_equalTo(@1);
    }];
    
   
    UIView *grayView = [[UIView alloc] init];
    [backgroundView addSubview:grayView];
    [grayView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(0);
        make.top.equalTo(line.mas_bottom).offset(0);
        make.right.equalTo(backgroundView).offset(0);
        make.bottom.equalTo(backgroundView).offset(0);
    }];
    grayView.backgroundColor = rgba(251, 251, 251, 1);
    
    ByHomeTitleValueView *leftView = [[ByHomeTitleValueView alloc] init];
    [backgroundView addSubview:leftView];
    [leftView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(0);
        make.centerY.equalTo(grayView).offset(0);
        make.size.mas_equalTo(CGSizeMake((SCREEN_WIDTH - 1) / 2.0, 70));
    }];
    leftView.titleLabel.text = @"本期销量(元)";
    leftView.titleLabel.font = FONT(12);
    leftView.titleLabel.textColor = [UIColor grayColor];
    leftView.valueLabel.textColor = BY_THEME_COLOR;

    
    ByHomeTitleValueView *rightView = [[ByHomeTitleValueView alloc] init];
    [backgroundView addSubview:rightView];
    [rightView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(backgroundView).offset(0);
        make.centerY.equalTo(grayView).offset(0);
        make.size.mas_equalTo(CGSizeMake((SCREEN_WIDTH - 1) / 2.0, 70));
    }];
    rightView.titleLabel.text = @"奖池金额(元)";
    rightView.titleLabel.font = FONT(12);
    rightView.titleLabel.textColor = [UIColor grayColor];
    rightView.valueLabel.textColor = BY_THEME_COLOR;
    leftView.valueLabel.text = [self balanceFormatFromStr:_netModel.sale_money];
    rightView.valueLabel.text = [self balanceFormatFromStr:_netModel.next_all_money];
    
    UILabel *line1 = [[UILabel alloc] init];
    [grayView addSubview:line1];
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(grayView).offset(-20);
        make.centerX.equalTo(grayView).offset(0);
        make.size.mas_equalTo(CGSizeMake(1, 50));
    }];
    line1.backgroundColor = BY_LINE_COLOR;
}


- (NSString *)balanceFormatFromStr:(NSString*)string{
    if (![NSString isPureNumandCharacters:string]) {
        return string;
    }
    NSNumberFormatter *numFormatter = [[NSNumberFormatter alloc] init];
    [numFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
    NSNumber *num = [numFormatter numberFromString:string];
    NSString *tempStr = [numFormatter stringFromNumber:num];
    return tempStr;
}




@end
